﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace TanmiaGrp.Basis.Specification
{
    public abstract class BaseSpecification<T> : ISpecification<T>
    {
        public Expression<Func<T, bool>> Predicate { get; protected set; }

        public IFetchStrategy<T> FetchStartegy { get; protected set; }

        public Expression<Func<T, int>> Selection { get; protected set; }

        /// <summary>
        /// Represent the index of the page which will be retrieved.
        /// Default value -1, mean no paging applied.
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// Represent the size of the page which will be retrieved.
        /// Default value -1, mean no paging applied.
        /// </summary>
        public int PageSize { get; set; }

        #region ISpecification<T> Members

        public bool IsSatisfiedBy(T entity)
        {
            return new[] { entity }.AsQueryable().Any(Predicate);
        }

        #endregion
    }
}
